//
//  NotificationPmlistData.m
//
//  Created by lianchuang  on 14-12-18
//  Copyright (c) 2014 __MyCompanyName__. All rights reserved.
//

#import "NotificationPmlistData.h"


NSString *const kNotificationPmlistDataSummary = @"summary";
NSString *const kNotificationPmlistDataDateline = @"dateline";
NSString *const kNotificationPmlistDataUid = @"uid";
NSString *const kNotificationPmlistDataMessage = @"message";
NSString *const kNotificationPmlistDataUsername = @"username";
NSString *const kNotificationPmlistDataSubject = @"subject";
NSString *const kNotificationPmlistDataType = @"type";
NSString *const kNotificationPmlistDataPmid = @"pmid";

NSString *const kNotificationPmlistDataAvatar = @"avatar";
NSString *const kNotificationPmlistDataRecvusername = @"recvusername";
NSString *const kNotificationPmlistDataUrl = @"url";
NSString *const kNotificationPmlistDataRecvuid = @"recvuid";
NSString *const kNotificationPmlistDataPcid = @"pcid";
NSString *const kNotificationPmlistDataTid = @"tid";






@interface NotificationPmlistData ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation NotificationPmlistData

@synthesize summary = _summary;
@synthesize dateline = _dateline;
@synthesize uid = _uid;
@synthesize message = _message;
@synthesize username = _username;
@synthesize subject = _subject;
@synthesize type = _type;
@synthesize pmid = _pmid;
@synthesize avatar = _avatar;
@synthesize recvusername = _recvusername;
@synthesize url =_url;
@synthesize recvuid = _recvuid;
@synthesize pcid = _pcid;
@synthesize tid = _tid;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.summary = [self objectOrNilForKey:kNotificationPmlistDataSummary fromDictionary:dict];
            self.dateline = [self objectOrNilForKey:kNotificationPmlistDataDateline fromDictionary:dict];
            self.uid = [self objectOrNilForKey:kNotificationPmlistDataUid fromDictionary:dict];
            self.message = [self objectOrNilForKey:kNotificationPmlistDataMessage fromDictionary:dict];
            self.username = [self objectOrNilForKey:kNotificationPmlistDataUsername fromDictionary:dict];
            self.subject = [self objectOrNilForKey:kNotificationPmlistDataSubject fromDictionary:dict];
            self.type = [[self objectOrNilForKey:kNotificationPmlistDataType fromDictionary:dict] doubleValue];
            self.pmid = [self objectOrNilForKey:kNotificationPmlistDataPmid fromDictionary:dict];
        
        self.avatar = [self objectOrNilForKey:kNotificationPmlistDataAvatar fromDictionary:dict];
        self.recvusername = [self objectOrNilForKey:kNotificationPmlistDataRecvusername fromDictionary:dict];
        self.url = [self objectOrNilForKey:kNotificationPmlistDataUrl fromDictionary:dict];
        self.recvuid = [self objectOrNilForKey:kNotificationPmlistDataRecvuid fromDictionary:dict];
        self.pcid = [self objectOrNilForKey:kNotificationPmlistDataPcid fromDictionary:dict];
        self.tid = [self objectOrNilForKey:kNotificationPmlistDataTid fromDictionary:dict];




    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.summary forKey:kNotificationPmlistDataSummary];
    [mutableDict setValue:self.dateline forKey:kNotificationPmlistDataDateline];
    [mutableDict setValue:self.uid forKey:kNotificationPmlistDataUid];
    [mutableDict setValue:self.message forKey:kNotificationPmlistDataMessage];
    [mutableDict setValue:self.username forKey:kNotificationPmlistDataUsername];
    [mutableDict setValue:self.subject forKey:kNotificationPmlistDataSubject];
    [mutableDict setValue:[NSNumber numberWithDouble:self.type] forKey:kNotificationPmlistDataType];
    [mutableDict setValue:self.pmid forKey:kNotificationPmlistDataPmid];
    
    [mutableDict setValue:self.avatar forKey:kNotificationPmlistDataAvatar];
    [mutableDict setValue:self.recvusername forKey:kNotificationPmlistDataRecvusername];
    [mutableDict setValue:self.url forKey:kNotificationPmlistDataUrl];
    [mutableDict setValue:self.recvuid forKey:kNotificationPmlistDataRecvuid];
    [mutableDict setValue:self.pcid forKey:kNotificationPmlistDataPcid];
    [mutableDict setValue:self.tid forKey:kNotificationPmlistDataTid];



    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.summary = [aDecoder decodeObjectForKey:kNotificationPmlistDataSummary];
    self.dateline = [aDecoder decodeObjectForKey:kNotificationPmlistDataDateline];
    self.uid = [aDecoder decodeObjectForKey:kNotificationPmlistDataUid];
    self.message = [aDecoder decodeObjectForKey:kNotificationPmlistDataMessage];
    self.username = [aDecoder decodeObjectForKey:kNotificationPmlistDataUsername];
    self.subject = [aDecoder decodeObjectForKey:kNotificationPmlistDataSubject];
    self.type = [aDecoder decodeDoubleForKey:kNotificationPmlistDataType];
    self.pmid = [aDecoder decodeObjectForKey:kNotificationPmlistDataPmid];
    
    self.avatar = [aDecoder decodeObjectForKey:kNotificationPmlistDataAvatar];
    self.recvusername = [aDecoder decodeObjectForKey:kNotificationPmlistDataRecvusername];
    self.url = [aDecoder decodeObjectForKey:kNotificationPmlistDataUrl];
    self.recvuid = [aDecoder decodeObjectForKey:kNotificationPmlistDataRecvuid];
    self.pcid = [aDecoder decodeObjectForKey:kNotificationPmlistDataPcid];
    self.tid = [aDecoder decodeObjectForKey:kNotificationPmlistDataTid];


    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_summary forKey:kNotificationPmlistDataSummary];
    [aCoder encodeObject:_dateline forKey:kNotificationPmlistDataDateline];
    [aCoder encodeObject:_uid forKey:kNotificationPmlistDataUid];
    [aCoder encodeObject:_message forKey:kNotificationPmlistDataMessage];
    [aCoder encodeObject:_username forKey:kNotificationPmlistDataUsername];
    [aCoder encodeObject:_subject forKey:kNotificationPmlistDataSubject];
    [aCoder encodeDouble:_type forKey:kNotificationPmlistDataType];
    [aCoder encodeObject:_pmid forKey:kNotificationPmlistDataPmid];
    
    [aCoder encodeObject:_avatar forKey:kNotificationPmlistDataAvatar];
    [aCoder encodeObject:_recvusername forKey:kNotificationPmlistDataRecvusername];
    [aCoder encodeObject:_url forKey:kNotificationPmlistDataUrl];
    [aCoder encodeObject:_recvusername forKey:kNotificationPmlistDataRecvuid];
    [aCoder encodeObject:_pcid forKey:kNotificationPmlistDataPcid];
    [aCoder encodeObject:_tid forKey:kNotificationPmlistDataTid];


}

- (id)copyWithZone:(NSZone *)zone
{
    NotificationPmlistData *copy = [[NotificationPmlistData alloc] init];
    
    if (copy) {

        copy.summary = [self.summary copyWithZone:zone];
        copy.dateline = [self.dateline copyWithZone:zone];
        copy.uid = [self.uid copyWithZone:zone];
        copy.message = [self.message copyWithZone:zone];
        copy.username = [self.username copyWithZone:zone];
        copy.subject = [self.subject copyWithZone:zone];
        copy.type = self.type;
        copy.pmid = [self.pmid copyWithZone:zone];
        
        copy.avatar = [self.avatar copyWithZone:zone];
        copy.recvusername = [self.recvusername copyWithZone:zone];
        copy.url = [self.url copyWithZone:zone];
        copy.pcid = [self.pcid copyWithZone:zone];
        copy.tid = [self.tid copyWithZone:zone];


    }
    
    return copy;
}


@end
